package com.chif.goingplus.controller;

import com.chif.goingplus.pojo.Origin;
import com.chif.goingplus.service.OriginService;
import com.chif.goingplus.utils.JsonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/origin")
public class OriginController {


    @Autowired
    OriginService originService;

    @RequestMapping("/queryAll")
    public String getOrigin(){
        List<Origin> origins = originService.queryAllOrigin();
        return JsonUtils.getJson(origins);
    }

    @RequestMapping("/add")
    public String addOrigin(Origin origin){
        originService.addOrigin(origin);
        return "新增出发地成功"+origin.getOriid();
    }

    @RequestMapping("/update")
    public String update(Origin origin){
        originService.updateOrigin(origin);
        return "修改地点信息成功";
    }


    @RequestMapping("/delete")
    public String delete(int id){
        originService.deleteOriginById(id);
        return "删除地点信息成功";
    }
}
